Làm slider trong wordpress không cần plug-in

Có rất nhiều plugin để bạn tạo một slider cho trang webs của bạn trong wordpress. Và dĩ nhiên những slide ấy cũng rất chuyên nghiệp (nếu trả phí). Còn ở đây mình chỉ chia sẽ một cách gắn slider mà không phụ thuộc vào plugin thôi và nó cũng chỉ giới hạn trong phạm vi nào đó thôi.

Tạo thư mục với tên nivoslider trong thư mục theme của bạn.

Rồi tạo vào đó thư mục images để lưu trữ icon cho nút bấm qua trái và qua phải.
link download hình ảnh: link arrow icon  |   Link bullets icon
và các file lần lượt là :
jquery-nivoslider-option.js
jquery-nivoslider.js
nivoslider-css.css
nivoslider-default-css.css
nivoslider-meta-css.css
nivoslider.php

Code jquery-nivoslider-option.js

        var metaslider_48 = function($) {
$('#metaslider_48').nivoSlider({
boxCols:7,
boxRows:5,
pauseTime:3000,
effect:"random",
controlNav:false,
directionNav:true,
pauseOnHover:false,
animSpeed:600,
prevText:"<",
nextText:">",
slices:15,
manualAdvance:false
});
};
var timer_metaslider_48 = function() {
var slider = !window.jQuery ? window.setTimeout(timer_metaslider_48, 100) : !jQuery.isReady ? window.setTimeout(timer_metaslider_48, 1) : metaslider_48(window.jQuery);
};
timer_metaslider_48();

Code jquery-nivoslider.js

/*
* jQuery Nivo Slider v3.2
* http://nivo.dev7studios.com
*
* Copyright 2012, Dev7studios
* Free to use and abuse under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Meta Slider modifications: caption taken from 'data-title' attribute instead of 'title' attribute.
*/

(function(e){var t=function(t,n){var r=e.extend({},e.fn.nivoSlider.defaults,n);var i={currentSlide:0,currentImage:"",totalSlides:0,running:false,paused:false,stop:false,controlNavEl:false};var s=e(t);s.data("nivo:vars",i).addClass("nivoSlider");var o=s.children();o.each(function(){var t=e(this);var n="";if(!t.is("img")){if(t.is("a")){t.addClass("nivo-imageLink");n=t}t=t.find("img:first")}var r=r===0?t.attr("width"):t.width(),s=s===0?t.attr("height"):t.height();if(n!==""){n.css("display","none")}t.css("display","none");i.totalSlides++});if(r.randomStart){r.startSlide=Math.floor(Math.random()*i.totalSlides)}if(r.startSlide>0){if(r.startSlide>=i.totalSlides){r.startSlide=i.totalSlides-1}i.currentSlide=r.startSlide}if(e(o[i.currentSlide]).is("img")){i.currentImage=e(o[i.currentSlide])}else{i.currentImage=e(o[i.currentSlide]).find("img:first")}if(e(o[i.currentSlide]).is("a")){e(o[i.currentSlide]).css("display","block")}var u=e("<img/>").addClass("nivo-main-image");u.attr("src",i.currentImage.attr("src")).show();s.append(u);e(window).resize(function(){s.children("img").width(s.width());u.attr("src",i.currentImage.attr("src"));u.stop().height("auto");e(".nivo-slice").remove();e(".nivo-box").remove()});s.append(e('<div class="nivo-caption"></div>'));var a=function(t){var n=e(".nivo-caption",s);if(i.currentImage.attr("data-title")!=""&&i.currentImage.attr("data-title")!=undefined){var r=i.currentImage.attr("data-title");if(r.substr(0,1)=="#")r=e(r).html();if(n.css("display")=="block"){setTimeout(function(){n.html(r)},t.animSpeed)}else{n.html(r);n.stop().fadeIn(t.animSpeed)}}else{n.stop().fadeOut(t.animSpeed)}};a(r);var f=0;if(!r.manualAdvance&&o.length>1){f=setInterval(function(){d(s,o,r,false)},r.pauseTime)}if(r.directionNav){s.append('<div class="nivo-directionNav"><a class="nivo-prevNav">'+r.prevText+'</a><a class="nivo-nextNav">'+r.nextText+"</a></div>");e(s).on("click","a.nivo-prevNav",function(){if(i.running){return false}clearInterval(f);f="";i.currentSlide-=2;d(s,o,r,"prev")});e(s).on("click","a.nivo-nextNav",function(){if(i.running){return false}clearInterval(f);f="";d(s,o,r,"next")})}if(r.controlNav){i.controlNavEl=e('<div class="nivo-controlNav"></div>');s.after(i.controlNavEl);for(var l=0;l<o.length;l++){if(r.controlNavThumbs){i.controlNavEl.addClass("nivo-thumbs-enabled");var c=o.eq(l);if(!c.is("img")){c=c.find("img:first")}if(c.attr("data-thumb"))i.controlNavEl.append('<a class="nivo-control" rel="'+l+'"><img src="'+c.attr("data-thumb")+'" alt="" /></a>')}else{i.controlNavEl.append('<a class="nivo-control" rel="'+l+'">'+(l+1)+"</a>")}}e("a:eq("+i.currentSlide+")",i.controlNavEl).addClass("active");e("a",i.controlNavEl).bind("click",function(){if(i.running)return false;if(e(this).hasClass("active"))return false;clearInterval(f);f="";u.attr("src",i.currentImage.attr("src"));i.currentSlide=e(this).attr("rel")-1;d(s,o,r,"control")})}if(r.pauseOnHover){s.hover(function(){i.paused=true;clearInterval(f);f=""},function(){i.paused=false;if(f===""&&!r.manualAdvance){f=setInterval(function(){d(s,o,r,false)},r.pauseTime)}})}s.bind("nivo:animFinished",function(){u.attr("src",i.currentImage.attr("src"));i.running=false;e(o).each(function(){if(e(this).is("a")){e(this).css("display","none")}});if(e(o[i.currentSlide]).is("a")){e(o[i.currentSlide]).css("display","block")}if(f===""&&!i.paused&&!r.manualAdvance){f=setInterval(function(){d(s,o,r,false)},r.pauseTime)}r.afterChange.call(this)});var h=function(t,n,r){if(e(r.currentImage).parent().is("a"))e(r.currentImage).parent().css("display","block");e('img[src="'+r.currentImage.attr("src")+'"]',t).not(".nivo-main-image,.nivo-control img").width(t.width()).css("visibility","hidden").show();var i=e('img[src="'+r.currentImage.attr("src")+'"]',t).not(".nivo-main-image,.nivo-control img").parent().is("a")?e('img[src="'+r.currentImage.attr("src")+'"]',t).not(".nivo-main-image,.nivo-control img").parent().height():e('img[src="'+r.currentImage.attr("src")+'"]',t).not(".nivo-main-image,.nivo-control img").height();for(var s=0;s<n.slices;s++){var o=Math.round(t.width()/n.slices);if(s===n.slices-1){t.append(e('<div class="nivo-slice" name="'+s+'"><img src="'+r.currentImage.attr("src")+'" style="position:absolute; width:'+t.width()+"px; height:auto; display:block !important; top:0; left:-"+(o+s*o-o)+'px;" /></div>').css({left:o*s+"px",width:t.width()-o*s+"px",height:i+"px",opacity:"0",overflow:"hidden"}))}else{t.append(e('<div class="nivo-slice" name="'+s+'"><img src="'+r.currentImage.attr("src")+'" style="position:absolute; width:'+t.width()+"px; height:auto; display:block !important; top:0; left:-"+(o+s*o-o)+'px;" /></div>').css({left:o*s+"px",width:o+"px",height:i+"px",opacity:"0",overflow:"hidden"}))}}e(".nivo-slice",t).height(i);u.stop().animate({height:e(r.currentImage).height()},n.animSpeed)};var p=function(t,n,r){if(e(r.currentImage).parent().is("a"))e(r.currentImage).parent().css("display","block");e('img[src="'+r.currentImage.attr("src")+'"]',t).not(".nivo-main-image,.nivo-control img").width(t.width()).css("visibility","hidden").show();var i=Math.round(t.width()/n.boxCols),s=Math.round(e('img[src="'+r.currentImage.attr("src")+'"]',t).not(".nivo-main-image,.nivo-control img").height()/n.boxRows);for(var o=0;o<n.boxRows;o++){for(var a=0;a<n.boxCols;a++){if(a===n.boxCols-1){t.append(e('<div class="nivo-box" name="'+a+'" rel="'+o+'"><img src="'+r.currentImage.attr("src")+'" style="position:absolute; width:'+t.width()+"px; height:auto; display:block; top:-"+s*o+"px; left:-"+i*a+'px;" /></div>').css({opacity:0,left:i*a+"px",top:s*o+"px",width:t.width()-i*a+"px"}));e('.nivo-box[name="'+a+'"]',t).height(e('.nivo-box[name="'+a+'"] img',t).height()+"px")}else{t.append(e('<div class="nivo-box" name="'+a+'" rel="'+o+'"><img src="'+r.currentImage.attr("src")+'" style="position:absolute; width:'+t.width()+"px; height:auto; display:block; top:-"+s*o+"px; left:-"+i*a+'px;" /></div>').css({opacity:0,left:i*a+"px",top:s*o+"px",width:i+"px"}));e('.nivo-box[name="'+a+'"]',t).height(e('.nivo-box[name="'+a+'"] img',t).height()+"px")}}}u.stop().animate({height:e(r.currentImage).height()},n.animSpeed)};var d=function(t,n,r,i){var s=t.data("nivo:vars");if(s&&s.currentSlide===s.totalSlides-1){r.lastSlide.call(this)}if((!s||s.stop)&&!i){return false}r.beforeChange.call(this);if(!i){u.attr("src",s.currentImage.attr("src"))}else{if(i==="prev"){u.attr("src",s.currentImage.attr("src"))}if(i==="next"){u.attr("src",s.currentImage.attr("src"))}}s.currentSlide++;if(s.currentSlide===s.totalSlides){s.currentSlide=0;r.slideshowEnd.call(this)}if(s.currentSlide<0){s.currentSlide=s.totalSlides-1}if(e(n[s.currentSlide]).is("img")){s.currentImage=e(n[s.currentSlide])}else{s.currentImage=e(n[s.currentSlide]).find("img:first")}if(r.controlNav){e("a",s.controlNavEl).removeClass("active");e("a:eq("+s.currentSlide+")",s.controlNavEl).addClass("active")}a(r);e(".nivo-slice",t).remove();e(".nivo-box",t).remove();var o=r.effect,f="";if(r.effect==="random"){f=new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade","boxRandom","boxRain","boxRainReverse","boxRainGrow","boxRainGrowReverse");o=f[Math.floor(Math.random()*(f.length+1))];if(o===undefined){o="fade"}}if(r.effect.indexOf(",")!==-1){f=r.effect.split(",");o=f[Math.floor(Math.random()*f.length)];if(o===undefined){o="fade"}}if(s.currentImage.attr("data-transition")){o=s.currentImage.attr("data-transition")}s.running=true;var l=0,c=0,d="",m="",g="",y="";if(o==="sliceDown"||o==="sliceDownRight"||o==="sliceDownLeft"){h(t,r,s);l=0;c=0;d=e(".nivo-slice",t);if(o==="sliceDownLeft"){d=e(".nivo-slice",t)._reverse()}d.each(function(){var n=e(this);n.css({top:"0px"});if(c===r.slices-1){setTimeout(function(){n.animate({opacity:"1.0"},r.animSpeed,"",function(){t.trigger("nivo:animFinished")})},100+l)}else{setTimeout(function(){n.animate({opacity:"1.0"},r.animSpeed)},100+l)}l+=50;c++})}else if(o==="sliceUp"||o==="sliceUpRight"||o==="sliceUpLeft"){h(t,r,s);l=0;c=0;d=e(".nivo-slice",t);if(o==="sliceUpLeft"){d=e(".nivo-slice",t)._reverse()}d.each(function(){var n=e(this);n.css({bottom:"0px"});if(c===r.slices-1){setTimeout(function(){n.animate({opacity:"1.0"},r.animSpeed,"",function(){t.trigger("nivo:animFinished")})},100+l)}else{setTimeout(function(){n.animate({opacity:"1.0"},r.animSpeed)},100+l)}l+=50;c++})}else if(o==="sliceUpDown"||o==="sliceUpDownRight"||o==="sliceUpDownLeft"){h(t,r,s);l=0;c=0;var b=0;d=e(".nivo-slice",t);if(o==="sliceUpDownLeft"){d=e(".nivo-slice",t)._reverse()}d.each(function(){var n=e(this);if(c===0){n.css("top","0px");c++}else{n.css("bottom","0px");c=0}if(b===r.slices-1){setTimeout(function(){n.animate({opacity:"1.0"},r.animSpeed,"",function(){t.trigger("nivo:animFinished")})},100+l)}else{setTimeout(function(){n.animate({opacity:"1.0"},r.animSpeed)},100+l)}l+=50;b++})}else if(o==="fold"){h(t,r,s);l=0;c=0;e(".nivo-slice",t).each(function(){var n=e(this);var i=n.width();n.css({top:"0px",width:"0px"});if(c===r.slices-1){setTimeout(function(){n.animate({width:i,opacity:"1.0"},r.animSpeed,"",function(){t.trigger("nivo:animFinished")})},100+l)}else{setTimeout(function(){n.animate({width:i,opacity:"1.0"},r.animSpeed)},100+l)}l+=50;c++})}else if(o==="fade"){h(t,r,s);m=e(".nivo-slice:first",t);m.css({width:t.width()+"px"});m.animate({opacity:"1.0"},r.animSpeed*2,"",function(){t.trigger("nivo:animFinished")})}else if(o==="slideInRight"){h(t,r,s);m=e(".nivo-slice:first",t);m.css({width:"0px",opacity:"1"});m.animate({width:t.width()+"px"},r.animSpeed*2,"",function(){t.trigger("nivo:animFinished")})}else if(o==="slideInLeft"){h(t,r,s);m=e(".nivo-slice:first",t);m.css({width:"0px",opacity:"1",left:"",right:"0px"});m.animate({width:t.width()+"px"},r.animSpeed*2,"",function(){m.css({left:"0px",right:""});t.trigger("nivo:animFinished")})}else if(o==="boxRandom"){p(t,r,s);g=r.boxCols*r.boxRows;c=0;l=0;y=v(e(".nivo-box",t));y.each(function(){var n=e(this);if(c===g-1){setTimeout(function(){n.animate({opacity:"1"},r.animSpeed,"",function(){t.trigger("nivo:animFinished")})},100+l)}else{setTimeout(function(){n.animate({opacity:"1"},r.animSpeed)},100+l)}l+=20;c++})}else if(o==="boxRain"||o==="boxRainReverse"||o==="boxRainGrow"||o==="boxRainGrowReverse"){p(t,r,s);g=r.boxCols*r.boxRows;c=0;l=0;var w=0;var E=0;var S=[];S[w]=[];y=e(".nivo-box",t);if(o==="boxRainReverse"||o==="boxRainGrowReverse"){y=e(".nivo-box",t)._reverse()}y.each(function(){S[w][E]=e(this);E++;if(E===r.boxCols){w++;E=0;S[w]=[]}});for(var x=0;x<r.boxCols*2;x++){var T=x;for(var N=0;N<r.boxRows;N++){if(T>=0&&T<r.boxCols){(function(n,i,s,u,a){var f=e(S[n][i]);var l=f.width();var c=f.height();if(o==="boxRainGrow"||o==="boxRainGrowReverse"){f.width(0).height(0)}if(u===a-1){setTimeout(function(){f.animate({opacity:"1",width:l,height:c},r.animSpeed/1.3,"",function(){t.trigger("nivo:animFinished")})},100+s)}else{setTimeout(function(){f.animate({opacity:"1",width:l,height:c},r.animSpeed/1.3)},100+s)}})(N,T,l,c,g);c++}T--}l+=100}}};var v=function(e){for(var t,n,r=e.length;r;t=parseInt(Math.random()*r,10),n=e[--r],e[r]=e[t],e[t]=n);return e};var m=function(e){if(this.console&&typeof console.log!=="undefined"){console.log(e)}};this.stop=function(){if(!e(t).data("nivo:vars").stop){e(t).data("nivo:vars").stop=true;m("Stop Slider")}};this.start=function(){if(e(t).data("nivo:vars").stop){e(t).data("nivo:vars").stop=false;m("Start Slider")}};r.afterLoad.call(this);return this};e.fn.nivoSlider=function(n){return this.each(function(r,i){var s=e(this);if(s.data("nivoslider")){return s.data("nivoslider")}var o=new t(this,n);s.data("nivoslider",o)})};e.fn.nivoSlider.defaults={effect:"random",slices:15,boxCols:8,boxRows:4,animSpeed:500,pauseTime:3e3,startSlide:0,directionNav:true,controlNav:true,controlNavThumbs:false,pauseOnHover:true,manualAdvance:false,prevText:"Prev",nextText:"Next",randomStart:false,beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){},lastSlide:function(){},afterLoad:function(){}};e.fn._reverse=[].reverse})(jQuery)

Code nivoslider-css.css

/*
* jQuery Nivo Slider v3.2
* http://nivo.dev7studios.com
*
* Copyright 2012, Dev7studios
* Free to use and abuse under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/

/* The Nivo Slider styles */
.nivoSlider {
position:relative;
width:100%;
height:auto;
overflow: hidden;
}
.nivoSlider img {
position:absolute;
top:0px;
left:0px;
max-width: none;
}
.nivo-main-image {
display: block !important;
position: relative !important;
width: 100% !important;
}

/* If an image is wrapped in a link */
.nivoSlider a.nivo-imageLink {
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
border:0;
padding:0;
margin:0;
z-index:6;
display:none;
background:white;
filter:alpha(opacity=0);
opacity:0;
}
/* The slices and boxes in the Slider */
.nivo-slice {
display:block;
position:absolute;
z-index:5;
height:100%;
top:0;
}
.nivo-box {
display:block;
position:absolute;
z-index:5;
overflow:hidden;
}
.nivo-box img { display:block; }

/* Caption styles */
.nivo-caption {
position:absolute;
left:0px;
bottom:0px;
background:#000;
color:#fff;
width:100%;
z-index:8;
padding: 5px 10px;
opacity: 0.8;
overflow: hidden;
display: none;
-moz-opacity: 0.8;
filter:alpha(opacity=8);
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
.nivo-caption p {
padding:5px;
margin:0;
}
.nivo-caption a {
display:inline !important;
}
.nivo-html-caption {
display:none;
}
/* Direction nav styles (e.g. Next & Prev) */
.nivo-directionNav a {
position:absolute;
top:45%;
z-index:9;
cursor:pointer;
}
.nivo-prevNav {
left:0px;
}
.nivo-nextNav {
right:0px;
}
/* Control nav styles (e.g. 1,2,3...) */
.nivo-controlNav {
text-align:center;
padding: 15px 0;
}
.nivo-controlNav a {
cursor:pointer;
}
.nivo-controlNav a.active {
font-weight:bold;
}
.nivo-controlNav img {
display:inline; /* Unhide the thumbnails */
position:relative;
margin: 5px;
opacity: 0.7;
}
.nivo-controlNav .active img,
.nivo-controlNav img:hover {
opacity: 1;
}

Code nivoslider-default-css.css

/*
Skin Name: Nivo Slider Default Theme
Skin URI: http://nivo.dev7studios.com
Description: The default skin for the Nivo Slider.
Version: 1.3
Author: Gilbert Pellegrom
Author URI: http://dev7studios.com
Supports Thumbs: true
*/

.theme-default .nivoSlider {
position:relative;
-webkit-box-shadow: 0px 1px 5px 0px #4a4a4a;
-moz-box-shadow: 0px 1px 5px 0px #4a4a4a;
box-shadow: 0px 1px 5px 0px #4a4a4a;
}
.theme-default .nivoSlider img {
position:absolute;
top:0px;
left:0px;
display:none;
}
.theme-default .nivoSlider a {
border:0;
display:block;
}

.theme-default .nivo-controlNav {
text-align: center;
padding: 15px 0;
width: 100%;
z-index: 99;
}
.theme-default .nivo-controlNav a {
display:inline-block;
width:22px;
height:22px;
background:url(/wp-content/themes/casinotructuyen123/nivoslider/images/bullets.png) no-repeat;
text-indent:-9999px;
border:0;
margin: 0 2px;
}
.theme-default .nivo-controlNav a.active {
background-position:0 -22px;
}

.theme-default .nivo-directionNav a {
display:block;
width:30px;
height:30px;
background:url(/wp-content/themes/casinotructuyen123/nivoslider/images/arrows.png) no-repeat;
text-indent:-9999px;
border:0;
opacity: 0;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
}
.theme-default:hover .nivo-directionNav a { opacity: 1; }
.theme-default a.nivo-nextNav {
background-position:-30px 0;
right:15px;
}
.theme-default a.nivo-prevNav {
left:15px;
}

.theme-default .nivo-caption {
font-family: Helvetica, Arial, sans-serif;
}
.theme-default .nivo-caption a {
color:#fff;
border-bottom:1px dotted #fff;
}
.theme-default .nivo-caption a:hover {
color:#fff;
}

.theme-default .nivo-controlNav.nivo-thumbs-enabled {
width: 100%;
}
.theme-default .nivo-controlNav.nivo-thumbs-enabled a {
width: auto;
height: auto;
background: none;
margin-bottom: 5px;
}
.theme-default .nivo-controlNav.nivo-thumbs-enabled img {
display: block;
height: auto;
}

Code nivoslider-meta-css.css

/**
* The files in /assets are unmodified.
* This file contains
* - resets, in an attempt to ensure sliders display properly in all themes
* - modifications to the default sliders CSS
*/

/* general resets */
.metaslider {
position: relative;
z-index: 0;
}

.metaslider .caption {
padding: 5px 10px;
word-wrap: break-word;
}

.metaslider .caption-wrap {
position: absolute;
bottom: 0;
left: 0;
background: black;
color: white;
opacity: 0.7;
margin: 0;
display: block;
width: 100%;
line-height: 1.4em;
}

.metaslider img {
height: auto;
padding: 0;
margin: 0;
-moz-user-select: none;
}

.metaslider a {
outline: none;
}

.metaslider .theme-default .nivoSlider {
-webkit-box-shadow: 0 0 0;
-moz-box-shadow: 0 0 0;
box-shadow: 0 0 0;
}

.metaslider.ms-left {
float: left;
margin: 0 20px 20px 0;
}

.metaslider.ms-right {
float: right;
margin: 0 0 20px 20px;
}

.metaslider li:before,
.metaslider li:after {
content: "" !important;
display: none !important;
bottom: auto !important;
margin: 0 !important;
}

.metaslider .caption-wrap .caption img {
width: auto;
}

/** quick resets **/
.article .metaslider ul,
.article .metaslider ol,
.article .metaslider li,
.article .metaslider img,
.art-article .metaslider ul,
.art-article .metaslider ol,
.art-article .metaslider li,
.art-article .metaslider img,
#widgets .metaslider ul,
#widgets .metaslider ol,
#widgets .metaslider li,
#widgets .metaslider img,
.entry .metaslider ul,
.entry .metaslider ol,
.entry .metaslider li,
.entry .metaslider img,
#content .metaslider ul,
#content .metaslider ol,
#content .metaslider li,
#content .metaslider img,
.entry-content .metaslider ul,
.entry-content .metaslider ol,
.entry-content .metaslider li,
.entry-content .metaslider img,
.metaslider .flexslider ul,
.metaslider .flexslider .slides li,
.metaslider .flexslider .slides ul,
.metaslider .flexslider .slides ol,
.metaslider .flexslider .flex-direction-nav,
.metaslider .flexslider .flex-direction-nav li,
*[class*='-article'] .metaslider img {
border: 0;
margin: 0;
list-style-type: none;
list-style: none;
padding: 0;
line-height: normal;
max-width: none;
max-height: none;
}

.metaslider .slides img {
width: 100%;
display: block;
}

Code nivoslider.php

<!-- meta slider -->
<div class='metaslider metaslider-nivo metaslider-48 ml-slider' style='width: 100%;'>
<div id='metaslider_container_48'>
<div class='slider-wrapper theme-default'>
<div class='ribbon'></div>
<div class='nivoSlider' id='metaslider_48'>
<?php
$loop = new WP_Query(array('post_type' => 'feature', 'posts_per_page' => -1, 'orderby'=> 'ASC'));
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $url = get_post_meta($post->ID, "url", true);
if($url!='') {
echo '<a href="'.$url.'">';
echo the_post_thumbnail('full');
echo '</a>';
} else {
echo the_post_thumbnail('full');
} ?>
<?php the_content();?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</div>
</div>
<!--// meta slider-->

Dán đoạn code dưới đây vào file function.php

//Insert jQuery from Google Libraries
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}


//Insert nivoslider 2 plugin
function nivoslider() {
wp_enqueue_script( 'jquery-nivoslider', get_stylesheet_directory_uri() . '/nivoslider/jquery-nivoslider.js', array('jquery') );
wp_enqueue_script( 'jquery-nivoslider-option', get_stylesheet_directory_uri() . '/nivoslider/jquery-nivoslider-option.js', array('jquery') );
wp_enqueue_style( 'nivoslider-css', get_stylesheet_directory_uri() . '/nivoslider/nivoslider-css.css');
wp_enqueue_style( 'nivoslider-meta-css', get_stylesheet_directory_uri() . '/nivoslider/nivoslider-meta-css.css');
wp_enqueue_style( 'nivoslider-default-css', get_stylesheet_directory_uri() . '/nivoslider/nivoslider-default-css.css');
}
add_action( 'wp_enqueue_scripts', 'nivoslider' );


// Custom Post types for Feature project on home page
add_action('init', 'create_feature');
function create_feature() {
$feature_args = array(
'labels' => array(
'name' => __( 'Feature Slider' ),
'singular_name' => __( 'Feature Slider' ),
'add_new' => __( 'Add New Feature Slider' ),
'add_new_item' => __( 'Add New Feature Slider' ),
'edit_item' => __( 'Edit Feature Slider' ),
'new_item' => __( 'Add New Feature Slider' ),
'view_item' => __( 'View Feature Slider' ),
'search_items' => __( 'Search Feature Slider' ),
'not_found' => __( 'No feature project found' ),
'not_found_in_trash' => __( 'No feature project found in trash' )
),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'menu_position' => 20,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type('feature',$feature_args);
}
add_filter("manage_feature_edit_columns", "feature_edit_columns");

function feature_edit_columns($feature_columns){
$feature_columns = array(
"cb" => "<input type="checkbox" />",
"title" => "Title",
);
return $feature_columns;
}


//Add Meta Boxes
//http://wp.tutsplus.com/tutorials/plugins/how-to-create-custom-wordpress-writemeta-boxes/

add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add()
{
add_meta_box( 'my-meta-box-id', 'Link to Project', 'cd_meta_box_cb', 'feature', 'normal', 'high' );
}

function cd_meta_box_cb( $post )
{
$url = get_post_meta($post->ID, 'url', true);
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' ); ?>

<p>
<label for="url">Project url</label>
<input type="text" name="url" id="url" value="<?php echo $url; ?>" style="width:350px" />
</p>

<?php
}

add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;

// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;

// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchors can only have href attribute
)
);

// Probably a good idea to make sure your data is set
if( isset( $_POST['url'] ) )
update_post_meta( $post_id, 'url', wp_kses( $_POST['url'], $allowed ) );
}

Đặt đoạn code dưới đây vào vị trí mà bạn muốn hiển thị slide

 <?php if(is_front_page()):?> 
<?php include_once(get_stylesheet_directory(). 'nivoslider/nivoslider.php'); ?>
<?php endif; ?>

Code dành cho phần feature slider trong wp-admin, dán code này vào trong file style.css

/* Home page featured slider
-----------------------------------------------------------*/
#featured-slider {
float:left;
width:940px; height:280px;
margin:0 10px;
position:relative;
}
#featured-slider #slides {
position:absolute;
top:0px;
left:0px;
z-index:100;
}
#featured-slider .slides_container {
width:940px;
overflow:hidden;
position:relative;
display:none;
background:#FFF;
}
#featured-slider .slides_container div.slide {
width:940px;
height:280px;
display:block;
}
#featured-slider .caption {
z-index:500;
position:absolute;
top: 30px; left:670px;
height:220px;
width:240px;
font-size:12px;
line-height:16px;
color:#000;
}
#featured-slider .caption h2 {
font-size:18px;
line-height:22px;
margin-bottom:10px;
}

#featured-slider #slides .next, #slides .prev {
position:absolute;
top:112px;
left:-10px;
width:30px;
height:37px;
display:block;
z-index:101;
text-indent:-99999em;
background: url(images/larr.gif);
}
#featured-slider #slides .next {
left:926px;
background: url(images/rarr.gif);
}

Leave a Comment

sơn epoxy / sơn sàn epoxy / cửa lưới chống muỗi / vách ngăn lướii chống muỗi / cửa lùa chống muỗi / vệ sinh công nghiệp / đánh bóng sàn bê tông / vệ sinh nhà máy / dịch vụ giặt thảmm / vệ sinh nhà hàng / vệ sinh tòa nhà / dịch vụ vệ sinh kính / vệ sinh khách sạn / vệ sinh chung cư / dịch vụ cắt cỏ / đánh bóng kính / diệt côn trùng / diệt mối / diệt kiến / diệt muỗi / diệt ruồi / diệt gián / diệt chuột / dọn bể nước ngầm / phụ kiện mái che / cơ khí chế tạo / mái che di động / rèm nhựa / vách nhựa ngăn phòng lạnh / rèm nhựa phòng lạnh / dù che nắng / mái kéo di động / nhà bạt di động / mái xếp di động / mái hiên di động / thay bạt mái hiên di động / bạt che nắng / phụ kiện mái che di động / mái che sân thượng / mái che quán cafe / mái che di động miền bắc / mái che di động miền nam / bạt che di động hcm /